package com.livestocksolutions.ui;

import com.livestocksolutions.R;
import com.livestocksolutions.intent.BaseActivity;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/* -- Version History --
 *  1.0 : 06 September 2012 - Initial version.
 */

/**
 * A base class to create the layout for the list of paddocks/Locations
 * @author Adam Parr
 * @version 1.0
 * 
 * @.modified 08 September 2012
 */
public class ViewLocationPaddockArrayAdapter extends BaseArrayAdapter {
	/**
	 * Size of the allowable array passed
	 */
	public static final int SIZE = 3;
	/**
	 * Unique ID for each position within the String[position][{@value #ID}] array passed in the Constructor.
	 */
	public static final int ID = 0;
	/**
	 * Name position within the String[position][{@value #NAME}] array passed in the Constructor.
	 */
	public static final int NAME = 1;
	/**
	 * Description of the Location/Paddock position within the String[position][{@value #DESCRIPTION}]
	 * array passed in the Constructor.
	 */
	public static final int DESCRIPTION = 2;
 
	/**
	 * Constructor
	 * @param context The current context.
	 * @param values The Paddock/Location to represent in the ListView.
	 */
	public ViewLocationPaddockArrayAdapter(BaseActivity context, String[][] values) {
		super(context, values);
	}
 
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		final View rowView = super.getView(position, convertView, parent);
		
		TextView locationName = (TextView) rowView.findViewById(R.id.locationName);
		TextView locationDescription = (TextView) rowView.findViewById(R.id.locationDescription);

		locationName.setText(values[position][NAME]);
		locationDescription.setText(values[position][DESCRIPTION]);
		
		locationName.addTextChangedListener(new TextWatcher() {
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
			public void onTextChanged(CharSequence s, int start, int before, int count) {}

			public void afterTextChanged(Editable s) {
				values[position][NAME]=s.toString();
			}
		});
		
		locationDescription.addTextChangedListener(new TextWatcher() {
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
			public void onTextChanged(CharSequence s, int start, int before, int count) {}

			public void afterTextChanged(Editable s) {
				values[position][DESCRIPTION]=s.toString();
			}
		});
		return rowView;
	}
}

